home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: bitfields, how big can their elements be?
- Date: Sat, 16 Mar 96 22:38:18 GMT
- Organization: none
- Message-ID: <827015898snz@genesis.demon.co.uk>
- References: <4i2lab$ili@hobbes.cc.uga.edu> <TANMOY.96Mar12075107@qcd.lanl.gov> <4i4c8dINNsde@keats.ugrad.cs.ubc.ca> <4icc3a$g9i@airdmhor.gen.nz>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4icc3a$g9i@airdmhor.gen.nz>
- gumboot@airdmhor.gen.nz "Simon Hosie" writes:
-
- >Kazimir Kylheku:
- >> With GCC I tried making bitfields "long" and "short". This is an odd
- > locution;
- >> the compiler will actually prevent a "short" field from being more than 16
- >> bits, but long can be 32. It's strange that the GNU compiler allows these
- >> modifiers for bitfields! I'm going to have to look this up in the standard
- > the
- >> first chance I get.
-
- The standard says (6.5.2.1):
-
- "A bit-field shall have a type that is a qualified or unqualified version of
- one of int, unsigned int, or signed int."
-
- However this isn't in a constraints section so a "long" or "short" bitfield
- results in undefined behaviour but the compiler is not required to issue
- a diagnostic. Therefore this is a legitimate candidate for a compiler
- defined language extension.
-
- > I'm fairly certain that they're supposed to be limited to
- >(CHAR_BIT * sizeof(int)) bits.
-
- If the code follows the standard (which implies that you are using int,
- unsigned int or signed int) then that is correct. Once you march off into
- undefined behaviour the compiler can extend the language with whatever rules
- it likes. (Actually I'm going to query that in comp.std.c since there is
- also a constraint applicable here).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-